/**
 *  pipe.h - Related routines and structs of pipe.
 *
 *  Copyright (C) 2008-2010 ZhangHu
 *  All rights reserved.
 *  E-MAIL: anmnmnly@gmail.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
#ifndef __PIPE_H__
#define __PIPE_H__

#include "include/types.h"

#ifndef UNIT_DEBUG
#include "include/mem.h"
#include "include/irq.h"
#include "include/core.h"
#endif


typedef struct pipe {
    int32 send_id;     // ID of task that sends data to pipe.
    int32 rev_id;      // ID of task that receives data from pipe.
    uint32 size;       // The size of pipe.
    uint32 used;       // The number of used space of pipe.
    void **start;       // Pointer to the start address of pipe.
    void **end;         // Pointer to the end address of pipe.
    void **in;          // Pointer to the write position of pipe.
    void **out;         // Pointer to the read position pipe.
} pipe_t;

// pipeInit - It creates a new pipe.
extern pipe_t *pipeInit(int32 SendID, // ID of sending task.
                        int32 RevID,  // ID of receiving task.
                        uint32 Size); // The size of pipe.

// pipeSend - Sending a message to a pipe.
extern bool_t pipeSend(pipe_t *pPipe,  // Pointer to the pipe
                       void *pMsg);    // Pointer to the message

extern void *pipeRev(pipe_t *pPipe);   // Pointer to the pipe

// Get current used space of pipe.
extern int32 pipeGetUsed(const pipe_t *pPipe);

// Clear a pipe
extern void pipeClear(pipe_t *pPipe);

// Delete a pipe
extern void pipeDel(pipe_t *pPipe);


#endif

